﻿using System;
using System.Collections;
using System.Collections.Generic;
using Microsoft.Xna.Framework.Content;

namespace DARE
{
    public sealed class CModelTag : IEnumerable<KeyValuePair<string, object>>
    {
        #region Fields

        private Dictionary<string, object> m_tags;

        #endregion

        #region Property

        [ContentSerializer]
        private Dictionary<string, object> Tags
        {
            get { return m_tags; }
            set
            {
                if (m_tags != value)
                    m_tags = value;
            }
        }

        #endregion

        #region CTOR

        public CModelTag()
        {
            m_tags = new Dictionary<string, object>();
        }

        #endregion

        #region Method

        public void Add(string key, object obj)
        {
            if (m_tags.ContainsKey(key))
                m_tags[key] = obj;
            else
                m_tags.Add(key, obj);
        }

        public bool ContainsKey(string key)
        {
            return this.m_tags.ContainsKey(key);
        }

        public object this[String key]
        {
            get
            {
                if (this.m_tags.ContainsKey(key))
                    return this.m_tags[key];
                return null;
            }
            set
            {
                this.Tags[key] = value;
        }
        }

        public IEnumerator<KeyValuePair<string, object>> GetEnumerator()
        {
            return this.m_tags.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return this.m_tags.GetEnumerator();
        }

        #endregion
    }
}
